      SUBROUTINE VECM50GAL(KEY,VECIN,VECOUT)
      IMPLICIT REAL*8 (A-H,O-Z)
C
C THIS ROUTINE ROTATES CARTERSIAN VECTORS BETWEEN THE MEAN OF 1950.0
C COORDINATE SYSTEM AND THE GALACTIC COORDINATE SYSTEM. BOTH ARE
C GEOCENTRIC.
C
C THE GALACTIC POLE AND GALACTIC CENTER DIRECTIONS ARE TAKEN FROM THE
C TEXT 'ASTRONOMY' BY  L W FREDRICK, 9TH EDITION, 1971. VALUES VERIFIED
C FROM OTHER SOURCES. THE DIRECTIONS ARE THOSE DECIDED UPON BY THE
C INTERNATIONAL ASTRONOMICAL UNION IN 1958.
C
C VARIABLE DIM TYPE I/O DESCRIPTION
C -------- --- ---- --- -----------
C
C KEY       1  I*4   I  FLAG INDICATING THE 'FROM' AND 'TO' COORDINATE
C                       SYSTEMS.
C
C                       = NEGATIVE, FROM GALACTIC TO 1950.0
C                       = OTHERWISE, FROM 1950.0 TO GALACTIC
C
C VECIN     3  R*8   I  THE VECTOR IN THE 'FROM' SYSTEM. ANY UNITS.
C
C VECOUT    3  R*8   O  THE VECTOR IN THE 'TO' SYSTEM. SAME UNITS AS
C                       VECIN. IN THE CALLING PROGRAM, VECIN AND VECOUT
C                       MAY BE THE SAME ARRAY.
C
C***********************************************************************
C
C BY C PETRUZZO, GSFC/742, 12/84.
C   MODIFIED.....
C
C***********************************************************************
C
      REAL*8 HALFPI / 1.570796326794897D0 /
      REAL*8 PI     / 3.141592653589793D0 /
      REAL*8 TWOPI  / 6.283185307179586D0 /
      REAL*8 DEGRAD / 57.29577951308232D0 /
      REAL*8 DEGHR/15.D0/
      INTEGER INIT/1/
      REAL*8 GCENTER(3),XGALACT(3),YGALACT(3),ZGALACT(3)
      REAL*8 GALM50(3,3),M50GAL(3,3),VECIN(3),VECOUT(3)
C
C *******************************
C * ONCE-PER-RUN INITIALIZATION *
C *******************************
C
      IF(INIT.EQ.1) THEN
        INIT = 0
C
C      ZRA,ZDEC GIVES THE DIRECTION OF THE GALACTIC NORTH POLE.
        ZRA =  (12.D0 + 49.D0/60.D0)*DEGHR/DEGRAD    ! = 12H, 49M
        ZDEC = 27.4D0/DEGRAD                         ! = 27.4 DEG
C
C      CRA,CDEC GIVES THE DIRECTION TO GALACTIC CENTER WHICH IS ON
C      THE ON THE X-AXIS.
        CRA =  (17.D0 + 42.4D0/60.D0)*DEGHR/DEGRAD   ! = 17H, 42.4M
        CDEC =  -(28.D0 + 55.D0/60.D0)/DEGRAD        ! = -28 DEG, 55 MIN
C
C      GET GALACTIC SYSTEM AXES RELATIVE TO THE 1950.0 COORDINATE SYSTEM
        CALL XYZSPH(1,CRA,CDEC,1.D0,GCENTER,1.D0)  ! 89.9919 DEG FROM Z.
        CALL XYZSPH(1,ZRA,ZDEC,1.D0,ZGALACT,1.D0)
        CALL UCROSS(ZGALACT,GCENTER,YGALACT)
        CALL UCROSS(YGALACT,ZGALACT,XGALACT)
C
C      SET THE MATRIX TAKING VECTOR COORDS FROM 1950.0 TO GALACTIC
        DO 10 I=1,3
        M50GAL(I,1) = XGALACT(I)
        M50GAL(I,2) = YGALACT(I)
   10   M50GAL(I,3) = ZGALACT(I)
C
C      SET THE MATRIX TAKING VECTORS FROM GALACTIC COORDS TO 1950.0
        CALL MTXFLIP33(M50GAL,GALM50)
C
        END IF
C
C
C ***********************
C * ROTATATE THE VECTOR *
C ***********************
C
      IF(KEY.LT.0) THEN
C      FROM GALACTIC TO 1950.0
        CALL VECROT(M50GAL,VECIN,VECOUT)
C
      ELSE
C      FROM 1950.0 TO GALACTIC
        CALL VECROT(GALM50,VECIN,VECOUT)
        END IF
C
C
      RETURN
      END
